
from PIL import Image


def split_png():
    print("split_png")
    input_path = "./utils/img/piece_set.png"
    name_list = [
        ["棋子-将.png", "棋子-士.png", "棋子-象.png", "棋子-马.png", "棋子-车.png", "棋子-炮.png", "棋子-卒.png"],
        ["棋子-红帅.png", "棋子-红士.png", "棋子-红相.png", "棋子-红马.png", "棋子-红车.png", "棋子-红炮.png", "棋子-红兵.png"],
    ]
    desc = []
    for row in range(2):
        for col in range(7):
            box = (0 + col*48, 0 + row * 48, 0 + col*48 + 46, 0 + row * 48 + 46)
            desc.append([name_list[row][col], box])

    # desc = [
    #     ["棋子-将.png", (0, 0, 46, 46)],
    #     ["棋子-士.png", (48, 0, 94, 46)],
    #     ["棋子-士.png", (48, 0, 94, 46)],
    # ]
    with Image.open(input_path) as img:
        width, height = img.size
        print("width:", width, height)

        for item in desc:
            name, box = item[:]
            tile = img.crop(box)
            tile.save(f"./utils/img/{name}", format='PNG')
    pass
